var express = require('express');
var sd = require('silly-datetime');
var exec = require('child_process').exec;

var app = express();

app.use('/', express.static(__dirname + '/template'));

app.get('/get', function(req, res){
    var getcmd = 'raspistill -t 10 -w 800 -h 600 -o ~/Downloads/Labeyes/template/pic/'
    var picurl = './pic/'
    var time = sd.format(new Date(), 'YYYYMMDD-HHmmss');
    console.log('req:' + time);
    console.log(req.headers["user-agent"]);
    getcmd = getcmd + time + '.jpg'
    picurl = picurl + time + '.jpg'
    exec(getcmd, function(err, stdout, stderr){
        res.json({"picurl" : picurl, "pictime" : time});
    })
});

app.listen(3000);
